Editor.Resource = function () {
  var shape;
  var element;
  var deckEdit;	
  var impl;
  var superType;
  return {
    init: function (u,i, t) {
      shape = new Editor.Shape();
      if (i != undefined) {
        impl = i;
      } else {
        impl = this;
      }
      superType = t;
      //alert("Resource "+u);
      shape.init(impl,u, t);
      element = new Editor.Element();
      element.init();
      shape._resize(Editor.CONFIG.RESOURCE_SHAPE_WIDTH, Editor.CONFIG.RESOURCE_SHAPE_HEIGHT);
      deckEdit = new Editor.DeckEdit();
      deckEdit.init(shape);
    },
    getInfo: function () {
      var prefix = element.getNamespace().getPrefix();
      var uri = element.getNamespace().getUri();
      var str = '';
      if (Editor.CONFIG.DEBUG) {
        var str = 'Information:\n';
      }
     /* if (prefix != '' && uri != '') {
        str += prefix;// + ' = ' + uri;
      } else {
        str += 'no namespace';
      }*/
      str = superType;
      if (Editor.CONFIG.DEBUG) {
        str += '\n( x:' + impl.getX();
        str += ' ; y:' + impl.getY();
        str += ' ; w:' + impl.getWidth();
        str += ' ; h:' + impl.getHeight() + ' )';
        str += '\nuuid: ' + impl.getUuid();
      }
      return str;
    },
    getNamespace: function () {
      return element.getNamespace();
    },
    setNamespace: function (n) {
      element.setNamespace(n);
    },
    getName: function () {
      return element.getName();
    },
    setName: function (n) {
      element.setName(n);
    },
    getText: function () {
      var t = element.getNamespace().getPrefix();
      if(impl.getTypeClass() == 'property'){
        t = element.getName();
        //t=t.replace("http://inference-web.org/2.0/pml-justification.owl#", "pmlj:");
        //t=t.replace("http://inference-web.org/2.0/pml-provenance.owl#", "pmlp:");
        //t=element.getName();
      }else if(impl.getTypeClass() == 'blank'){
        t = element.getNamespace().getUri();
      }else{
        //if (t == '') {
          t = '<' + element.getName() + '>';
        //} else {
        //  t = element.getNamespace().getPrefix() + element.getName();
        //}
      }
      
      
      if(impl.getTypeClass() == 'blank'){
        t = element.getName();
      }
      return t;
    },
    _remove: function () {
      shape._remove(impl);
      deckEdit.remove();
    },
    remove: function () {
      shape.remove(impl);
      deckEdit.remove();
    },
    draw: function () {
      shape.draw(impl);
      deckEdit.draw();
      deckEdit.redraw();
    },
    toFront: function () {
      shape.toFront(impl);
      deckEdit.toFront(impl);
    },
    moveTo: function (x, y) {
      shape.moveTo(x, y);
    },
    translate: function (dx, dy) {
      shape._translate(dx,dy);
      deckEdit.translate(dx,dy);
    },
    _translate: function (dx, dy) {
      shape._translate(dx,dy);
      deckEdit.translate(dx,dy);
    },
    _resize: function (dw, dh) {
      shape._resize(dw, dh);
      deckEdit.redraw();
    },
    resize: function (dw, dh) {
      shape.resize(dw, dh);
      deckEdit.redraw();
    },
    getTextAttr: function () {
      return Editor.CONFIG.SHAPE_ATTR_TEXT;
    },
    figure: function () {
      return Editor.STATE.CANVAS.rect(shape.getX(), shape.getY(), shape.getWidth(), shape.getHeight(), Editor.CONFIG.RESOURCE_SHAPE_ROUNDED).
      attr(Editor.CONFIG.RESOURCE_SHAPE_ATTR);
    },
    getShapeAttr: function () {
      return Editor.CONFIG.RESOURCE_SHAPE_ATTR;
    },
    getUuid: function () {
      return shape.getUuid();
    },
    isDeleted: function () {
      return shape.isDeleted();
    },
    getX: function () {
      return shape.getX();
    },
    getY: function () {
      return shape.getY();
    },
    getWidth: function () {
      return shape.getWidth();
    },
    getHeight: function () {
      return shape.getHeight();
    },
    toString: function () {
      return 'Resource-->(' + element.toString() + ' ; ' + shape.toString() + ')'
    },
    select: function () {
      shape.select(impl);
    },
    unselect: function () {
      Editor.Util.unselect(shape);
      shape.unselect();	
    },
    frameResize: function () {
      return shape.frameResize();
    },
    saveIni: function (e) {
      shape.saveIni(e);
    },
    getIniPosx: function () {
      return shape.getIniPosx();
    },
    getIniPosy: function () {
      return shape.getIniPosy();
    },
    mousedown: function (e) {
      if (!Editor.Util.isDragging()) {
        shape.mousedown(e);
      }
    },
    mouseover: function () {
      if (!Editor.Util.isDragging()) {
        shape.mouseover();
        deckEdit.mouseover();
      }
    },
    mouseout: function () {
      if (!Editor.Util.isDragging()) {
        shape.mouseout();
        deckEdit.mouseout();
      }
    },
    click: function () {
      if (!Editor.Util.isDragging()) {
        shape.click();
        deckEdit.toFront();
      }
    },
    updateText: function () {
      shape.updateText();
    },
    getMinWidth: function () {
      return shape.getMinWidth();
    },
    getMinHeight: function () {
      return shape.getMinHeight();
    },
    showEdit: function () {
      suffix = "";
      midfix = "";
      if(superType.indexOf(Editor.PML.J.PREFIX) == 0){
        suffix = 'J';
        midfix = 'j';
      }else if(superType.indexOf(Editor.PML.T.PREFIX) == 0){
        suffix = 'T';
        midfix = 't';
      }
      Editor.STATE.SHAPETOUPDATE = impl;
      $('#name'+suffix).val(element.getName());
      $('#namespacePrefix'+suffix).val(element.getNamespace().getPrefix());
      $('#namespaceUri'+suffix).val(element.getNamespace().getUri());
      $('#dialogAddResource'+suffix).jqm({overlay: 40, modal: true}).jqmShow();
      $("input[name='pml"+midfix+"class']").removeAttr('checked');
      $("input[name='pml"+midfix+"class'][value='"+superType+"']").attr('checked', 'checked');
      $("input[name='pml"+midfix+"class'][value!='"+superType+"']").parent().hide();
      $("div[name=maincat"+suffix+"]").show();
      $("input[name='pml"+midfix+"class'][value='"+superType+"']").parent().show();
      if(impl.getTypeClass() == 'blank'){
        Editor.Util.blankDialogOn();
      }else{
        $("#isBlank"+suffix).attr('checked', false);
        Editor.Util.blankDialogOff();
      }
    },
    getDeckEdit: function () {
      return deckEdit;
    },
    getImplementation: function () {
      return impl;
    },
    onmouseup: function () {
      
    },
    toObject: function () {
      return {
        'element': element.toObject(),
        'shape': shape.toObject(),
      }
    },
    getSuperType: function(){
      return superType;
    },
    setSuperType: function(t){
      superType = t;
    }
  }
}
